#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
	int fd;
	ssize_t recv_size;
    char buf[100];
	fd = open("./love.txt", O_RDONLY);
    if(fd==-1){
        perror("fd open failed");
        return 1;
    }
    int fd2;
    fd = open("./love2.txt", O_RDONLY|O_CREAT|O_WRONLY ,0664 );
    if(fd2==-1){
        perror("fd2 open failed");
        return 1;
    }

    recv_size=read(fd, buf, 100);
    while(recv_size > 0){
        write(STDOUT_FILENO, buf, recv_size);
        write(fd2, buf, recv_size); 
    }
    if(recv_size==-1){
        perror("read failed");
        close(fd);
        close(fd2);
        return 1;
    }
	printf("%s\n", buf);
	return 0;
}